package comxin.demo1.nodestream;

import org.junit.Test;

import java.io.*;

public class FileInputStreamdemo_01 {
    @Test
    //字节流读写文本文件（一次一个字节）
    public void method1() throws IOException {
        FileInputStream fileInputStream1 = new FileInputStream("E://itcast//窗里窗外.txt");
        FileOutputStream fileOutputStream1=new FileOutputStream("IOdemo02.txt");
        int temp;
        while ((temp=fileInputStream1.read())!=-1){
            fileOutputStream1.write((byte)temp);
        }
        fileInputStream1.close();
        fileOutputStream1.close();
    }

    //字节流读写图片（一次一个字节数组）
    @Test
    public void method2() throws IOException {
        FileInputStream fileInputStream2 = new FileInputStream("E://itcast//mn.jpg");
        FileOutputStream fileOutputStream2=new FileOutputStream("mn.jpg");
        byte[] bytes=new byte[1024];
        while (fileInputStream2.read(bytes)!=-1){
            fileOutputStream2.write(bytes);
        }
        fileInputStream2.close();
        fileOutputStream2.close();
    }


}
